<?php
/**
 * Created by PhpStorm
 * User: Jhinwy
 * Date: 7/24/24
 * Time: 3:22 PM
 */

namespace app\adminapi\controller\return_rule;


use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\return_rule\ReturnRuleLists;
use app\adminapi\logic\return_rule\ReturnRuleLogic;
use app\adminapi\validate\return_rule\ReturnRuleValidate;


/**
 * ReturnRule控制器
 * Class ReturnRuleController
 * @package app\adminapi\controller
 */
class ReturnRuleController extends BaseAdminController
{


    /**
     * @notes 获取列表
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/03/06 10:32
     */
    public function lists()
    {
        return $this->dataLists(new ReturnRuleLists());
    }


    /**
     * @notes 添加
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/03/06 10:32
     */
    public function add()
    {
        $params             = (new ReturnRuleValidate())->post()->goCheck('add');
        $params['admin_id'] = $this->adminId;
        $result             = ReturnRuleLogic::add($params);
        if (true === $result) {
            return $this->success('添加成功', [], 1, 1);
        }
        return $this->fail(ReturnRuleLogic::getError());
    }


    /**
     * @notes 编辑
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/03/06 10:32
     */
    public function edit()
    {
        $params = (new ReturnRuleValidate())->post()->goCheck('edit');
        $result = ReturnRuleLogic::edit($params);
        if (true === $result) {
            return $this->success('编辑成功', [], 1, 1);
        }
        return $this->fail(ReturnRuleLogic::getError());
    }


    /**
     * @notes 删除
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/03/06 10:32
     */
    public function delete()
    {
        $params = (new ReturnRuleValidate())->post()->goCheck('delete');
        ReturnRuleLogic::delete($params);
        return $this->success('删除成功', [], 1, 1);
    }


    /**
     * @notes 获取详情
     * @return \think\response\Json
     * @author likeadmin
     * @date 2024/03/06 10:32
     */
    public function detail()
    {
        $params = (new ReturnRuleValidate())->goCheck('detail');
        $result = ReturnRuleLogic::detail($params);
        return $this->data($result);
    }


    /**
     * @notes  更改状态
     * @return \think\response\Json
     * @author heshihu
     * @date 2022/2/21 10:15
     */
    public function updateStatus()
    {
        $params = (new ReturnRuleValidate())->post()->goCheck('status');

        return ReturnRuleLogic::updateStatus($params) ?
            $this->success('修改成功', [], 1, 1) : $this->fail('修改失败');
    }

}
